﻿var confirmDlg;
var infoDlg;
var errorDlg;

function genFakeSubmitBtn(btnName,form)
{
    var fakeSubmit = $("<input type='hidden' name='" + btnName + "' id='" + btnName + "' /> ");
 

    fakeSubmit.val("Y");
    fakeSubmit.appendTo(form);

   
  
    return fakeSubmit;
}

function showConfirmDefault(message,buttonName)
{
   
    var okFunc = function (event)
    {
        var validatemyform = $("#mainForm").validate();
        var isValid = $('#mainForm').valid();
        if (isValid) {
            var form = $('#mainForm');
            var fakeSubmit = genFakeSubmitBtn(buttonName, form)
            form.submit();
            fakeSubmit.remove();
            event.preventDefault();
            closeConfirm();
        } else
        {

            validatemyform.focusInvalid();
            showErrorDlg("โปรดระบุข้อมูลให้ครบ");
           
            event.preventDefault();
            closeConfirm();
        }
    }


    return showConfirm(message, okFunc, null);
}
function showConfirm(message,yesFunc,noFunc)
{
  //  เเเหห
    confirmDlg.dialog("open");
    if (message != null)
    {
        $("#contentConfirm").text(message);
    }
    var buttons = confirmDlg.dialog("option", "buttons");
    buttons["OK"] = function () { alert("button1 code here"); };
    buttons["Cancel"] = function () { $(this).dialog("close"); };

    if (yesFunc != null)
    {
        buttons["OK"] = yesFunc;
    }
    if (noFunc != null)
    {
        buttons["Cancel"] = noFunc;
    }
  
    
    confirmDlg.dialog("option", "buttons", buttons); // setter
   

    return false;
}
function closeConfirm()
{
    confirmDlg.dialog("close");
}


function showInfoDlg() {
    infoDlg.dialog("open");
} 

function showInfoDlg(message) {
    infoDlg.dialog("open");
    $("#contentInfo").text(message);
}

function showErrorDlg() {
    errorDlg.dialog("open");
}

function showErrorDlg(message)
{
    errorDlg.dialog("open");
    $("#contentError").text(message);
    
    
}